package controller;

import service.CalculateService;
import service.Result;

import java.util.Map;

/**
 * @author yuzk
 * @date 2018/1/17
 */
public class CalculateController {

    private CalculateService service = CalculateService.getInstance();

    /**
     * 处理分发过来的请求,对应到各个接口
     *
     * @param path
     * @param params
     * @return
     */
    public Result handleRequest(String path, Map<String, Object> params) {
        if(path.equals(Path.Calculate.ADD)){
            return add(Double.parseDouble((String)params.get("a")), Double.parseDouble((String)params.get("b")));
        }
        return Result.error("path not match");
    }

    /**
     * 加
     * @param a
     * @param b
     * @return
     */
    public Result add(Double a, Double b) {
        if(a == null || b == null){
            return Result.error("param not null");
        }
        return Result.success(service.add(a,b));
    }


    private CalculateController(){ }
    private static CalculateController calculateController = new CalculateController();
    public static CalculateController getInstance(){
        return calculateController;
    }
}
